/* GUI CONVERTED from apvoiqa.p (converter v1.76) Thu Jun 13 19:47:39 2002 */
/* apvoiqa.p - AP VOUCHER INQUIRY                                       */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                  */
/* All rights reserved worldwide.  This is an unpublished work.         */
/* $Revision: 1.19.1.12 $                                                         */
/*K0MW         */
/*V8:ConvertMode=Report                                                 */
/* was apvoiq.p until G042                                              */
/* REVISION: 1.0     LAST MODIFIED: 11/04/86   BY: PML                  */
/* REVISION: 6.0     LAST MODIFIED: 06/11/91   BY: MLV *D687*           */
/* REVISION: 6.0     LAST MODIFIED: 06/26/91   BY: MLV *D595*           */
/* REVISION: 6.0     LAST MODIFIED: 08/01/91   BY: MLV *D801*           */
/* REVISION: 7.0     LAST MODIFIED: 08/20/91   BY: MLV *F002*           */
/* REVISION: 7.0     LAST MODIFIED: 01/11/92   BY: MLV *F082*           */
/* REVISION: 7.0     LAST MODIFIED: 03/16/92   BY: TMD *F260*           */
/* REVISION: 7.3     LAST MODIFIED: 09/02/92   BY: MLV *G042*           */
/*                                  11/19/92   By: jcd *G339*           */
/*                                  02/24/93   by: jms *G744*           */
/*                                  04/06/93   by: jms *G910*           */
/* REVISION: 7.4     LAST MODIFIED: 04/01/94   BY: pcd *H310*           */
/*                                  04/01/94   BY: pcd *H329*           */
/*                                  09/15/94   BY: ljm *GM57*           */
/*                                  03/30/95   BY: jzw *G0JX*           */
/*                                  06/01/95   BY: jzw *G0P2*           */
/* REVISION: 8.6     LAST MODIFIED: 10/08/97   BY: ckm *K0MW*           */
/* REVISION: 8.6E    LAST MODIFIED: 02/23/98   BY: *L007* A. Rahane     */
/* REVISION: 8.6E    LAST MODIFIED: 04/23/98   BY: *L00M* D. Sidel      */
/* REVISION: 8.6E    LAST MODIFIED: 05/14/98   BY: *L00Z* AWe           */
/* REVISION: 8.6E    LAST MODIFIED: 05/20/98   BY: *K1Q4* Alfred Tan    */
/* REVISION: 8.6E    LAST MODIFIED: 06/02/98   BY: *L03L* Brenda Milton */
/* REVISION: 8.6E    LAST MODIFIED: 08/28/98   BY: *L07P* GYK           */
/* REVISION: 8.6E    LAST MODIFIED: 09/17/98   BY: *J2YQ* Satish Chavan */
/* REVISION: 8.6E    LAST MODIFIED: 09/21/98   BY: *L08W* Russ Witt     */
/* REVISION: 8.6E    LAST MODIFIED: 10/06/98   BY: *L09C* Santhosh Nair */
/* REVISION: 8.6E    LAST MODIFIED: 12/22/98   BY: *L0CY* Hemali Desai  */
/* REVISION: 9.0     LAST MODIFIED: 03/10/99   BY: *M0B3* Michael Amaladhas */
/* REVISION: 9.0     LAST MODIFIED: 03/13/99   BY: *M0BD* Alfred Tan        */
/* REVISION: 9.1     LAST MODIFIED: 08/07/99   BY: *N01J* Brenda Milton     */
/* REVISION: 9.1     LAST MODIFIED: 12/14/99   BY: *M0GT* Raphael Thoppil   */
/* REVISION: 9.1      LAST MODIFIED: 03/24/00  BY: *N08T* Annasaheb Rahane  */
/* REVISION: 9.1      LAST MODIFIED: 08/07/00  BY: *M0QQ* Rajesh Lokre      */
/* REVISION: 9.1      LAST MODIFIED: 08/11/00  BY: *N0KK* jyn               */
/* REVISION: 9.1      LAST MODIFIED: 08/21/00  BY: *N0MG* Mudit Mehta       */
/* Old ECO marker removed, but no ECO header exists *F0PN*                  */
/* Revision: 1.19.1.11     BY: Anil Sudhakaran  DATE: 08/24/01  ECO: *N11S* */
/* $Revision: 1.19.1.12 $             BY: Lena Lim         DATE: 06/14/02  ECO: *P089* */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/


/*GUI preprocessor directive settings */
&SCOPED-DEFINE PP_GUI_CONVERT_MODE REPORT

{mfdeclre.i}

/* EXTERNAL LABEL INCLUDE */
{gplabel.i}

/* ********** Begin Translatable Strings Definitions ********* */

&SCOPED-DEFINE apvoiqa_p_1 "Open Only"
/* MaxLen: Comment: */

/* ********** End Translatable Strings Definitions ********* */

define variable vend like ap_vend.
define variable ref like vo_ref.
define variable open_only like mfc_logical label {&apvoiqa_p_1}.
define variable type like ap_type format "x(12)".

define variable po          like vpo_po.
define variable vopo        like vpo_po.
define variable view-pos    like mfc_logical.

define variable invoice like vo_invoice.
define variable base_rpt like ap_curr.
define variable votype like vo_type.
define variable curr as character format "x(4)".
define variable match_found like mfc_logical no-undo.
define variable undo_all like mfc_logical no-undo.

define shared variable aptype like ap_type.

define new shared variable mc-rpt-curr like ap_curr no-undo.

{etrpvar.i &new = "new"}
{etvar.i   &new = "new"}
{eteuro.i}
define variable display_curr like base_rpt.

find first gl_ctrl no-lock.

/*GUI preprocessor Frame A define */
&SCOPED-DEFINE PP_FRAME_NAME A

FORM /*GUI*/ 
   
 RECT-FRAME       AT ROW 1 COLUMN 1.25
 RECT-FRAME-LABEL AT ROW 1 COLUMN 3 NO-LABEL VIEW-AS TEXT SIZE-PIXELS 1 BY 1
 SKIP(.1)  /*GUI*/
ref            colon 10
   vend           colon 42
   po             colon 68
   invoice        colon 10
   votype         colon 42
   open_only      colon 68
   base_rpt       colon 10
   curr           no-label
   et_report_curr colon 42
with frame a side-labels width 80 overlay no-underline no-attr-space NO-BOX THREE-D /*GUI*/.

 DEFINE VARIABLE F-a-title AS CHARACTER INITIAL "".
 RECT-FRAME-LABEL:SCREEN-VALUE in frame a = F-a-title.
 RECT-FRAME-LABEL:HIDDEN in frame a = yes.
 RECT-FRAME:HEIGHT-PIXELS in frame a =
  FRAME a:HEIGHT-PIXELS - RECT-FRAME:Y in frame a - 2.
 RECT-FRAME:WIDTH-CHARS IN FRAME a = FRAME a:WIDTH-CHARS - .5.  /*GUI*/

/*GUI preprocessor Frame A undefine */
&UNDEFINE PP_FRAME_NAME



/* SET EXTERNAL LABELS */
setFrameLabels(frame a:handle).

{wbrp02.i}
repeat:

   /* Initialize the format for base_rpt */
   base_rpt:format in frame a = "x(3)".

   if vend = ? then vend = "".

   if c-application-mode <> 'web' then
   update
      ref
      vend
      po
      invoice
      votype
      open_only
      base_rpt
      et_report_curr
   with frame a
   editing:

      if frame-field = "ref" then do for ap_mstr:
            /* FIND NEXT/PREVIOUS RECORD */
            {mfnp01.i ap_mstr ref ap_ref ap_type aptype ap_type_ref }
            if recno <> ? then do:
               ref = ap_ref.
               find vd_mstr where vd_addr = ap_vend no-lock no-error.
               if available vd_mstr then
               display
                  ref
                  vd_addr @ vend
               with frame a.
               find vo_mstr where vo_ref = ap_ref no-lock no-error.

               if available vo_mstr then do:
                  find first vpo_det where vpo_ref = vo_ref
                  no-lock no-error.
                  if available vpo_det then
                     display vpo_po @ po with frame a.
                  else
                     display ""     @ po with frame a.

                  display
                     vo_invoice  @ invoice
                     base_rpt
                     vo_type     @ votype
                  with frame a.
               end.

               recno = ?.
            end.
         end.
         else do:
            status input.
            readkey.
            apply lastkey.
         end.
      end.

      {wbrp06.i &command = update
         &fields = "  ref vend po invoice votype
           open_only base_rpt
           et_report_curr

           " &frm = "a"}

      if (c-application-mode <> 'web') or
         (c-application-mode = 'web' and
         (c-web-request begins 'data')) then do:

         status input "".

         if ref <> "" then do for ap_mstr:
               find ap_mstr where
                  ap_type = aptype
                  and ap_ref = ref
                  and ((ap_curr = base_rpt) or (base_rpt = ""))
                  use-index ap_type_ref
               no-lock no-error.
               if available ap_mstr then do:
                  vend = ap_vend.
                  display vend with frame a.
                  find vo_mstr where vo_ref = ap_ref and
                     (vo_curr = base_rpt or base_rpt = "")
                  no-lock no-error.

                  if available vo_mstr then do:
                     find first vpo_det where vpo_ref = vo_ref
                     no-lock no-error.
                     assign
                        po = if available vpo_det then vpo_po else ""
                        invoice = vo_invoice
                        votype = vo_type.
                     display po invoice votype with frame a.
                  end.
               end.
            end.

            if base_rpt = "" then
            do:
               /* Change the format for base_rpt */
               base_rpt:format in frame a = "x(7)".

               display getTermLabel("BASE",7) @  base_rpt
               with frame a.

            end. /* if base_rpt = "" */

            else display "" @ curr with frame a.

            if base_rpt <> "" then
               mc-rpt-curr = base_rpt.
            else mc-rpt-curr = base_curr.

            if et_report_curr <> "" then do:
               {gprunp.i "mcpl" "p" "mc-chk-valid-curr"
                  "(input et_report_curr,
                    output mc-error-number)"}
               if mc-error-number = 0
                  and et_report_curr <> mc-rpt-curr then do:

                  {gprunp.i "mcpl" "p" "mc-create-ex-rate-usage"
                     "(input et_report_curr,
                       input mc-rpt-curr,
                       input "" "",
                       input et_eff_date,
                       output et_rate2,
                       output et_rate1,
                       output mc-seq,
                       output mc-error-number)"}
               end.  /* if mc-error-number = 0 */
               if mc-error-number <> 0 then do:
                  {pxmsg.i &MSGNUM=mc-error-number &ERRORLEVEL=3}
                  if c-application-mode = "web" then return.
                  next-prompt et_report_curr with frame a.
                  undo, retry.
               end.  /* if mc-error-number <> 0 */
               else if et_report_curr <> mc-rpt-curr then do:

                  {gprunp.i "mcpl" "p" "mc-delete-ex-rate-usage"
                     "(input mc-seq)"}
               end.  /* else do */
            end.  /* if et_report_curr <> "" */
            if et_report_curr = "" or et_report_curr = mc-rpt-curr then
               assign
               mc-exch-line1 = ""
               mc-exch-line2 = ""
               et_report_curr = mc-rpt-curr.

         end.  /* if (c-application-mode <> 'web') ... */

         /* OUTPUT DESTINATION SELECTION */
         {gpselout.i &printType = "terminal"
                     &printWidth = 80
                     &pagedFlag = " "
                     &stream = " "
                     &appendToFile = " "
                     &streamedOutputToTerminal = " "
                     &withBatchOption = "no"
                     &displayStatementType = 1
                     &withCancelMessage = "yes"
                     &pageBottomMargin = 6
                     &withEmail = "yes"
                     &withWinprint = "yes"
                     &defineVariables = "yes"}
/*GUI*/ RECT-FRAME:HEIGHT-PIXELS in frame a = FRAME a:HEIGHT-PIXELS - RECT-FRAME:Y in frame a - 2.


         match_found = no.
         undo_all = no.

         /* VOUCHER NUMBER SELECTED, FIND THE ONE AP_MSTR AND VO_MSTR */
         if ref <> "" then
               loopb:
         do for ap_mstr:
            find ap_mstr where
               ap_type = aptype
               and ap_ref = ref
               and (ap_vend = vend or vend = "" )
               and ((ap_curr = base_rpt) or (base_rpt = ""))
               use-index ap_type_ref
            no-lock no-error.
            if not available ap_mstr then leave loopb.

            find first vpo_det where vpo_ref = ap_ref no-lock no-error.
            if not available vpo_det and po <> "" then leave loopb.

            find vo_mstr where vo_ref = ref
               and (vo_invoice = invoice or invoice = "" )
               and (vo_curr = base_rpt or base_rpt = "")
               and (vo_type = votype or votype = "" )
            no-lock no-error.
            if not available vo_mstr then leave loopb.
            match_found = yes.

/*fdn*/            {gprun.i ""hkapvoiqb.p""
               "(input recid(ap_mstr),
                 input recid(vo_mstr),
                 input (if available vpo_det
                 then recid(vpo_det) else ?),
                 input open_only,
                 input base_rpt,
                 input aptype,
                 input-output undo_all)"}

         end. /* LOOPB */

         /* VOUCHER NUMBER NOT SELECTED, VENDOR NUMBER SELECTED, */
         /* FIND ONE AP_MSTR AND VO_MSTR */
         /* FOR EACH VOUCHER FOR THAT VENDOR */
         else if vend <> "" then
               loopd:
         repeat for ap_mstr
               while not undo_all:
            find prev ap_mstr where ap_vend = vend
               and ap_type = aptype
               and ((ap_curr = base_rpt) or (base_rpt = ""))
               use-index ap_vend_date
            no-lock no-error.
            if not available ap_mstr then leave loopd.

            find first vpo_det where vpo_ref = ap_ref
               and (vpo_po = po or po = "")
            no-lock no-error.
            if not available vpo_det and po <> "" then next loopd.

            find vo_mstr where vo_ref = ap_ref
               and (vo_invoice = invoice or invoice = "" )
               and (vo_curr = base_rpt or base_rpt = "")
               and (vo_type = votype or votype = "" )
            no-lock no-error.
            if not available vo_mstr then next loopd.
            match_found = yes.

            {gprun.i ""hkapvoiqb.p""
               "(input recid(ap_mstr),
                 input recid(vo_mstr),
                 input (if available vpo_det
                 then recid(vpo_det) else ?),
                 input open_only,
                 input base_rpt,
                 input aptype,
                 input-output undo_all)"}

         end. /* LOOPD */

         /* IF VENDOR WAS NOT SELECTED BUT PO WAS SELECTED,   */
         /* THEN SCAN VPO_DET FILE FOR ALL THE VOUCHERS FOR   */
         /* THE ENTERED PO. INQUIRY WILL BE BY VENDOR         */
         /* THIS SECTION WILL DISPLAY ALL VOUCHERS PERTAINING */
         /* TO THE ENTERED PO IRRESPECTIVE OF THE PO VENDOR   */
         /* AND THE PAID TO VENDOR BEING SAME OR DIFFERENT    */

         else if po <> "" then
               loop-po:
         for each vpo_det
               fields(vpo_po vpo_ref)
               where vpo_po = po
         no-lock:
            
/*GUI*/ {mfguichk.i } /*Replace mfrpchk*/


            for first ap_mstr
               fields(ap_ref ap_curr ap_date
               ap_open ap_type ap_vend)
               where ap_type = aptype   and
               ap_ref  = vpo_ref
            no-lock:
            end.
            if not available ap_mstr then next loop-po.

            for first vo_mstr
               fields(vo_ref vo_type vo_invoice vo_curr)
               where vo_ref = ap_ref
               and (vo_invoice = invoice or invoice = "" )
               and (vo_curr = base_rpt or base_rpt = "" )
               and (vo_type = votype or votype = "" )
            no-lock:
            end.
            if not available vo_mstr then next loop-po.

            match_found = yes.

            {gprun.i ""hkapvoiqb.p""
               "(input recid(ap_mstr),
                 input recid(vo_mstr),
                 input (if available vpo_det
                 then recid(vpo_det) else ?),
                 input open_only,
                 input base_rpt,
                 input aptype,
                 input-output undo_all)"}
         end. /* END OF LOOP-PO */

         /* VOUCHER NUMBER NOT SELECTED, */
         /* VENDOR NUMBER NOT SELECTED,  */
         /* PO NUMBER NOT SELECTED,      */
         /* INVOICE NUMBER SELECTED,     */
         /* FIND VO_MSTR FOR THAT INVOICE NUMBER, AND MATCHING AP_MSTR, */
         /* FOR EACH VOUCHER WITH THAT INVOICE NUMBER */
         else if invoice <> "" then
               loop_invoice:
         for each vo_mstr where vo_invoice = invoice
               and (vo_curr = base_rpt or base_rpt = "")
               and (vo_type = votype or votype = "" )
               use-index vo_invoice
            no-lock
               while not undo_all:
            
/*GUI*/ {mfguichk.i } /*Replace mfrpchk*/

            find ap_mstr where ap_type = aptype
               and ap_ref = vo_ref
               and (ap_curr = base_rpt or base_rpt = "")
               use-index ap_type_ref
            no-lock no-error.
            if not available ap_mstr then next loop_invoice.
            find first vpo_det where vpo_ref = ap_ref
            no-lock no-error.
            match_found = yes.

            {gprun.i ""hkapvoiqb.p""
               "(input recid(ap_mstr),
                 input recid(vo_mstr),
                 input (if available vpo_det
                 then recid(vpo_det) else ?),
                 input open_only,
                 input base_rpt,
                 input aptype,
                 input-output undo_all)"}

         end. /* LOOP_INVOICE */

         /* VOUCHER NUMBER NOT SELECTED, */
         /* VENDOR NUMBER NOT SELECTED,  */
         /* PO NUMBER NOT SELECTED,      */
         /* INVOICE NUMBER NOT SELECTED, */
         /* FIND AP_MSTR AND MATCHING VO_MSTR, */
         /* FOR EACH VOUCHER WHICH MATCHES REMAINING SELECTION CRITERIA, */
         /* IN DESCENDING DATE SEQUENCE SO NEWEST VOUCHER IS FIRST */
         else
               loopf:
         for each ap_mstr where
               ap_mstr.ap_type = aptype
               and (ap_open or open_only = no)
               and ((ap_curr = base_rpt) or (base_rpt = ""))
            no-lock by ap_date descending
               while not undo_all:
            
/*GUI*/ {mfguichk.i } /*Replace mfrpchk*/


            find first vpo_det where vpo_ref = ap_ref
               and (vpo_po = po or po = "")
            no-lock no-error.
            if not available vpo_det and po <> "" then next loopf.

            find vo_mstr where vo_ref = ap_ref
               and (vo_invoice = invoice or invoice = "" )
               and (vo_type = votype or votype = "" )
               and (vo_curr = base_rpt or base_rpt = "")
            no-lock no-error.
            if not available vo_mstr then next loopf.
            match_found = yes.

            {gprun.i ""hkapvoiqb.p""
               "(input recid(ap_mstr),
                 input recid(vo_mstr),
                 input (if available vpo_det
                 then recid(vpo_det) else ?),
                 input open_only,
                 input base_rpt,
                 input aptype,
                 input-output undo_all)"}

         end. /* LOOPF */

         if not match_found then
         /* REMOVE FRAMES FROM PREVIOUS INQUIRY, */
         /* LEAVING THE SELECTION FRAME ONLY     */
         display "" with frame z no-box STREAM-IO /*GUI*/ .

         {mfreset.i}
/*GUI*/ {mfgrptrm.i} /*Report-to-Window*/

         {pxmsg.i &MSGNUM=8 &ERRORLEVEL=1}

      end. /* REPEAT */

      {wbrp04.i &frame-spec = a}
